<template>
  <div class="tablewrap" style="height: 100%;overflow-y:auto;">
    <div class="table-seareh">
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="课件库">
          <el-select v-model="listQuery.classifyId" placeholder="请选择">
            <el-option
              v-for="item in kjkOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"/>
          </el-select>
        </el-form-item>
        <el-form-item label="课件名称" prop="name">
          <el-input v-model="listQuery.name"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="stSearch">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      v-loading="listLoading"
      ref="sttable"
      :header-cell-style="rowClass"
      :data="list"
      class="tableScope"
      style="width: 100%"
      highlight-current-row
      @current-change="stHandleSelectionChange">
      <el-table-column :show-overflow-tooltip="true" prop="name" label="课件名称" width="200"/>
      <el-table-column prop="videoType" label="课件类型" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.videoType | videoType }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="remark" label="简介" show-overflow-tooltip/>
    </el-table>
    <div class="btn-pagion fix">
      <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getlist"/>
    </div>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination'
// import { queryVideoList, queryVideoRepoList } from '@/api/course/create'
export default {
  name: 'CourseWare',
  components: { Pagination },
  filters: {
    videoType(val) {
      if (val === 1) {
        return '音频'
      } else if (val === 2) {
        return 'pdf'
      } else if (val === 0) {
        return '视频'
      }
    }
  },
  data() {
    return {
      listLoading: false,
      listQuery: {
        page: 1,
        limit: 10,
        classifyId: '',
        name: ''
      },
      list: [],
      selectData: null,
      total: 0,
      kjkOptions: []
    }
  },
  created() {
    this.getQuesBankList()
    this.getlist()
  },
  methods: {
    rowClass({ row, rowIndex }) {
      return {
        padding: '5px 0',
        height: '20px',
        background: '#ffffff'
      }
    },
    getQuesBankList() {
      return new Promise((resolve, reject) => {
        queryVideoRepoList().then(response => {
          this.kjkOptions = response.data.data
          this.kjkOptions.unshift({
            name: '全部',
            id: ''
          })
        }).catch(error => {
          reject(error)
        })
      })
    },
    getlist(obj) {
      this.listLoading = true
      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit
      }
      query['id'] = this.listQuery.classifyId
      query['name'] = this.listQuery.name
      this.list = []
      return new Promise((resolve, reject) => {
        queryVideoList(query).then(response => {
          this.list = response.data.data.rows
          this.total = response.data.data.total
          this.listLoading = false
        }).catch(error => {
          this.listLoading = false
          reject(error)
        })
      })
    },
    stSearch() {
      this.getlist()
    },
    stHandleSelectionChange(arr) {
      this.selectData = arr
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss">
$mainColor: #18A5FD;
.tablewrap{
  .table-seareh{
    text-align: center;
    border-bottom: 1px solid #E2E3E8;
    margin-bottom: 20px;
  }
  .tableScope{
    padding: 0 20px;
  }
}
</style>
